<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group " style="padding-top: 5px">
        <div class="input-group" style="width:250px;float:left;padding-left: 5px;padding-right: 5px">
       		<span class="input-group-addon" >长度</span>
       		<input class="form-control" type='text' id='last' value="${last!}"/>
        </div>
        <div class="input-group" style="width:250px;float:left;padding-left: 5px;padding-right: 5px">
       		<span class="input-group-addon" >宽度</span>
       		<input class="form-control" type='text' id='width' value="${width!}"/>
        </div>
        <div class="input-group" style="width:250px;float:left;padding-left: 5px;padding-right: 5px">
       		<span class="input-group-addon" >高度</span>
       		<input class="form-control" type='text' id='height' value="${height!}"/>
        </div>
        <div class="input-group" style="width:250px;float:left;padding-left: 5px;padding-right: 5px">
       		<span class="input-group-addon" >重量</span>
       		<input class="form-control" type='text' id='weight' value="${weight!}"/>
        </div>
        <div class="input-group" style="width:250px;float:left;padding-left: 5px;padding-right: 5px">
       		<span class="input-group-addon" >保价</span>
       		<input class="form-control" type='text' id='insurance' value="${insurance!}"/>
        </div>
    </div>
    <div class="btn-group tool-button" >
			<button class="btn btn-primary navbar-btn" onclick="search()">查询</button>
	</div>
</header>
<div class="content-wrap">
    <div class="wrapper" style="min-height: 500px;">
        <div class="row mb15">
            <div class="col-lg-12">
                <form id="addRoleForm" class="form-horizontal stepy" method="post">
                    <div class="form-group no-b">
                        <div class="col-sm-8">
                            <div class="panel">
                            	<br>
                            	<div class="form-group">
	                            	<label for="name" class="col-sm-2 control-label">选择物流公司</label>
	
	                            	<div class="col-sm-8">
	                                <select id="logisticsId" name="logisticsId" class="form-control" onchange="select()" > 
						        		<% for(logistics in obj){ %>
						        			<% if(logisticsId == logistics.id) {%>
										     <option value=${logistics.id!} selected="selected">${logistics.name!}</option>
										    <%}else if(logisticsId != logistics.id) {%>  
										     <option value=${logistics.id!} >${logistics.name!}</option>
										    <%}%>
										<%}%>	
						        	</select>
                            		</div>
                        		</div>
                                <div class="panel-heading no-b">
                                    <h5>选择<b>目的地</b></h5>
                                </div>
                                <div class="panel-body">
                                    <div id="jsTreeMenu"></div>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <div class="panel">
                                <div class="panel-heading no-b">
                                    <h5><b>描述</b></h5>
                                </div>
                                <div id="menuDescript" class="panel-body">
                                    <div class='alert alert-info'>请勾选目的地</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script language="JavaScript">
    var jsTreeMenu;
    $(function () {
        jsTreeMenu = $("#jsTreeMenu").jstree({
                    plugins: ["wholerow", "checkbox"],
                    core: {
                        data: ${area!},
                        multiple:false
        			},
                checkbox: {
                    three_state: false
        }
    }).on("hover_node.jstree", function (e, data) {
        if (data.node.data)
            $("#menuDescript").text(data.node.data);
    }).on("dehover_node.jstree", function (e, data) {
        $("#menuDescript").html("<div class='alert alert-info'>请勾选目的地</div>");//清空菜单描述
    }).bind("loaded.jstree", function (e, data) {
        //立即加载树下所有节点

    });
    });
    function each(node, tree, nodes) {
        var p = tree.get_parent(node);
        if (p.length > 1) {
            if (nodes&&p&&nodes.indexOf(p)<0)
                nodes.push(p);
            each(p, tree, nodes);
        }
    }
    function search() {
    	var logisticsId = $("#logisticsId").val();
    	if(logisticsId.trim()==""){
    		Toast.warning("请选择物流公司");
    		return
    	}
    	var last = $("#last").val();
    	var width = $("#width").val();
    	var height = $("#height").val();
    	var weight = $("#weight").val();
    	var insurance = $("#insurance").val();
    	var reg = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
    	if(reg.test(last)){
    	}else {
    		Toast.warning("请输入正确的长度");
    		return
		}
    	if(reg.test(width)){
    	}else {
    		Toast.warning("请输入正确的宽度");
    		return
		}
    	if(reg.test(height)){
    	}else {
    		Toast.warning("请输入正确的高度");
    		return
		}
    	if(reg.test(weight)){
    	}else {
    		Toast.warning("请输入正确的重量");
    		return
		}
    	if(reg.test(insurance)){
    	}else {
    		Toast.warning("请输入正确的保价");
    		return
		}
        var tree = $.jstree.reference("#jsTreeMenu");
        var ids = tree.get_selected();
        //查询所选节点的所有父节点
        for (var i = 0; i < ids.length; i++) {
            var node = ids[i];
            each(node, tree, ids);
        }
        if (ids.length > 0) {
        	  $.post("${base}/platform/losys/freight/select" , {last: last, width: width, height:height, weight: weight, logistics: logisticsId, insurance: insurance}, function (data) {
        		 console.log(data);
                 /* if (data.code == 0) {
                     datatable.ajax.reload(null,false);
                 } else {
                     Toast.error(data.msg);
                 }
                 //重置按钮状态，关闭提示框
                 btn.button("reset");
                 dialog.modal("hide"); 
             }, "json"); */
         });
    } else {
        Toast.warning("请先选择目的地！");
    }
    }
    
    function select() {
    	var last = $("#last").val();
    	var width = $("#width").val();
    	var height = $("#height").val();
    	var weight = $("#weight").val();
    	var insurance = $("#insurance").val();
		if(last === ""){
			last = "null"
		}
		if(width === ""){
			width = "null"
		}
		if(height === ""){
			height = "null"
		}
		if(weight === ""){
			weight = "null"
		}
		if(insurance === ""){
			insurance = "null"
		}
		
    	window.location.href = "${base}/platform/losys/freight/index/"+$("#logisticsId").val()+ "/" + last + "/" + width + "/" + height + "/" + weight + "/" + insurance;
    	
	}
</script>
<%}%>